"""
启动检查脚本 - 检查各个模块是否可以正常导入
"""
import sys

def check_imports():
    """检查所有必要的导入"""
    errors = []
    
    print("=" * 60)
    print("检查依赖模块...")
    print("=" * 60)
    
    # 检查PyQt6
    try:
        from PyQt6.QtWidgets import QApplication
        print("[OK] PyQt6")
    except Exception as e:
        errors.append(f"[ERROR] PyQt6: {e}")
        print(f"[ERROR] PyQt6: {e}")
    
    # 检查sounddevice
    try:
        import sounddevice as sd
        print("[OK] sounddevice")
    except Exception as e:
        errors.append(f"[ERROR] sounddevice: {e}")
        print(f"[ERROR] sounddevice: {e}")
    
    # 检查numpy
    try:
        import numpy as np
        print("[OK] numpy")
    except Exception as e:
        errors.append(f"[ERROR] numpy: {e}")
        print(f"[ERROR] numpy: {e}")
    
    # 检查keyboard
    try:
        import keyboard
        print("[OK] keyboard")
    except Exception as e:
        errors.append(f"[ERROR] keyboard: {e}")
        print(f"[ERROR] keyboard: {e}")
    
    # 检查pystray
    try:
        import pystray
        print("[OK] pystray")
    except Exception as e:
        errors.append(f"[ERROR] pystray: {e}")
        print(f"[ERROR] pystray: {e}")
    
    # 检查Pillow
    try:
        from PIL import Image
        print("[OK] Pillow")
    except Exception as e:
        errors.append(f"[ERROR] Pillow: {e}")
        print(f"[ERROR] Pillow: {e}")
    
    print("\n" + "=" * 60)
    print("检查项目模块...")
    print("=" * 60)
    
    # 检查config模块
    try:
        from config.config_manager import ConfigManager
        print("[OK] config.config_manager")
    except Exception as e:
        errors.append(f"[ERROR] config_manager: {e}")
        print(f"[ERROR] config_manager: {e}")
    
    # 检查network模块
    try:
        from network.network_manager import NetworkManager
        print("[OK] network.network_manager")
    except Exception as e:
        errors.append(f"[ERROR] network_manager: {e}")
        print(f"[ERROR] network_manager: {e}")
    
    # 检查audio模块
    try:
        from audio.audio_manager import AudioManager
        print("[OK] audio.audio_manager")
    except Exception as e:
        errors.append(f"[ERROR] audio_manager: {e}")
        print(f"[ERROR] audio_manager: {e}")
    
    # 检查UI模块
    try:
        from ui.main_window import MainWindow
        print("[OK] ui.main_window")
    except Exception as e:
        errors.append(f"[ERROR] main_window: {e}")
        print(f"[ERROR] main_window: {e}")
    
    try:
        from ui.notification_windows import RecordingOverlay, SpeakingNotification
        print("[OK] ui.notification_windows")
    except Exception as e:
        errors.append(f"[ERROR] notification_windows: {e}")
        print(f"[ERROR] notification_windows: {e}")
    
    try:
        from ui.system_tray import SystemTray
        print("[OK] ui.system_tray")
    except Exception as e:
        errors.append(f"[ERROR] system_tray: {e}")
        print(f"[ERROR] system_tray: {e}")
    
    try:
        from ui.hotkey_manager import HotkeyManager
        print("[OK] ui.hotkey_manager")
    except Exception as e:
        errors.append(f"[ERROR] hotkey_manager: {e}")
        print(f"[ERROR] hotkey_manager: {e}")
    
    # 显示结果
    print("\n" + "=" * 60)
    if errors:
        print("[ERROR] 发现以下错误:")
        print("=" * 60)
        for error in errors:
            print(error)
        return False
    else:
        print("[SUCCESS] 所有模块检查通过！")
        print("=" * 60)
        print("\n可以尝试启动程序: python main.py")
        return True

if __name__ == "__main__":
    success = check_imports()
    sys.exit(0 if success else 1)

